<template>
  <div id="app">
    <router-view class="router-view" v-slot="{ Component }">
      <transition :name="transitionName">
        <keep-alive>
          <component :is="Component" />
        </keep-alive>
      </transition>
    </router-view>
  </div>
</template>
<script>
export default {
  data() {
    return {
      transitionName: "slide-left",
    };
  },
  // watch: {
  //   $route(to, from) {
  //     // 有主级到次级
  //     if (to.meta.index > from.meta.index) {
  //       this.transitionName = "slide-left"; // 向左滑动
  //     } else if (to.meta.index < from.meta.index) {
  //       // 由次级到主级
  //       this.transitionName = "slide-right";
  //     } else {
  //       this.transitionName = ""; //同级无过渡效果
  //     }
  //   },
  // },
};
</script>
<style>
#app {
  height: 100%;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.router-view {
  width: 100%;
  height: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}
</style>
